#include <wx/wx.h>

class EventFrame : public wxFrame
{
public:
    EventFrame(const wxString &title);

private:
    void OnButtonClick(wxCommandEvent &event);
    void OnMove(wxMoveEvent &event);

private:
    wxStaticText *st1;
    wxStaticText *st2;

private:
    DECLARE_EVENT_TABLE()
};

EventFrame::EventFrame(const wxString &title)
    : wxFrame(nullptr, wxID_ANY, title)
{
    wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
    wxButton *button = new wxButton(this, wxID_ANY, "Click me!");
    wxButton *button2 = new wxButton(this, wxID_ANY, "Quit!");

    wxSizer *hsizer = new wxBoxSizer(wxHORIZONTAL);
    hsizer->Add(button, 0, wxALL, 5);
    hsizer->Add(button2, 0, wxALL, 5);

    wxPanel *panel = new wxPanel(this, -1);
    st1 = new wxStaticText(panel, -1, wxT(""), wxPoint(10, 50));
    st2 = new wxStaticText(panel, -1, wxT(""), wxPoint(10, 80));

    Connect(wxEVT_MOVE, wxMoveEventHandler(EventFrame::OnMove));
    button2->Bind(wxEVT_BUTTON, [&](wxCommandEvent& event) { Close(); });
    Bind(wxEVT_CLOSE_WINDOW, [&](wxCloseEvent& event) { 
        wxMessageDialog *dlg = new wxMessageDialog(this, "Do you want to quit?", 
        "Quit", wxYES_NO |  wxNO_DEFAULT | wxICON_QUESTION);
        int ret = dlg->ShowModal();
        dlg->Destroy();

        if (ret == wxID_YES) {
            Destroy();
        }
        else
            event.Veto();
     });

    sizer->Add(hsizer, 0, wxALIGN_CENTER | wxALL, 5);
    sizer->Add(panel, 1, wxEXPAND);
    SetSizer(sizer);
    Centre();
}

BEGIN_EVENT_TABLE(EventFrame, wxFrame)
EVT_BUTTON(wxID_ANY, EventFrame::OnButtonClick)
END_EVENT_TABLE()

void EventFrame::OnButtonClick(wxCommandEvent &event)
{
    wxMessageBox("You clicked the button!");
}

void EventFrame::OnMove(wxMoveEvent& event)
{
  wxPoint size = event.GetPosition();
  st1->SetLabel(wxString::Format(wxT("x: %d"), size.x ));
  st2->SetLabel(wxString::Format(wxT("y: %d"), size.y ));
}

class EventApp : public wxApp
{
public:
    virtual bool OnInit();
};

bool EventApp::OnInit()
{
    EventFrame *frame = new EventFrame("Event Example");
    frame->Show();
    return true;
}

wxIMPLEMENT_APP(EventApp);